package com.starinside.wp.repository;

import com.starinside.wp.domain.Classes;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2017/7/6
 * *******************************
 */
@Repository
public interface ClassesRepository extends JpaRepository<Classes, String>, JpaSpecificationExecutor<Classes> {

    List<Classes> findByCategoryAndTargetObjectIdAndDeleted(Integer category, String targetObjectId, Boolean deleted);

    List<Classes> findByCategoryAndDeleted(Integer category, Boolean deleted);

    Classes findByNameAndAreaId(String name, String areaId);

    List<Classes> findByAreaId(String areaId);

    List<Classes> findByCategoryAndAreaId(Integer category, String areaId);

    List<Classes> findByAreaIdAndDeleted(String areaId, boolean deleted);

    List<Classes> findByAreaIdAndCategoryAndDeleted(String areaId, Integer category, boolean deleted);

    @Query(value = "SELECT c.* from rel_classes_teacher r left JOIN classes c on r.classesId = c.id where r.staffId = :staffId",nativeQuery = true)
    List<Classes> findByStaffId(@Param("staffId") String staffId);

    Long countByAreaIdAndDeleted(String areaId, boolean deleted);

    Long countByAreaIdAndCategoryAndDeleted(String areaId, Integer category, boolean deleted);

}
